package basic.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class CommonUtil {

    /**
     * 交换result数组的下标a和b的值
     * @param result
     * @param a     交换下标1
     * @param b     交换下标2
     * @return
     */
    public static int[] swap(int[] result,int a,int b){
        int temp=result[a];
        result[a]=result[b];
        result[b]=temp;
        return result;
    }
    public static Integer[] swap(Integer[] result,int a,int b){
        Integer temp=result[a];
        result[a]=result[b];
        result[b]=temp;
        return result;
    }

    /**
     * 生成随机数组
     * @param size      数组大小
     * @param limit     最大值,[-limit,limit]
     * @return
     */
    public static int[] generateArrays(int size,int limit){
        int[] res =new int[size];
        for (int i = 0; i < size; i++) {
            int res1 = (int)(Math.random()*(limit+1));  //[0,limit],int
            int res2 = (int)(Math.random()*(limit+1));  //[0,limit],int
            res[i]=res1-res2;
        }
        return res;
    }


    /**
     * 核实两个数组是否一致
     * @param res1  数组1
     * @param res2  数组2
     * @return  true/false
     */
    public static boolean checkArrays(int[] res1,int[] res2){

        String  res_a = Arrays.toString(res1);
        String  res_b =Arrays.toString(res2);
        if (res_a.equals(res_b)){
            return true;
        }else {
            return false;
        }
    }

    /**
     * 将数组转化为字符串
     * @param res int类型的数组
     * @return 字符串
     */
    public static String printArray(int[] res){
        String result = "";
        for (int re : res) {
            result+=re+",";
        }
        return result;
    }



}
